package com.hzvictory.hotel_system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
//import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hzvictory.hotel_system.common.annotation.Log;
import com.hzvictory.hotel_system.common.core.controller.BaseController;
import com.hzvictory.hotel_system.common.core.domain.AjaxResult;
import com.hzvictory.hotel_system.common.enums.BusinessType;
import com.hzvictory.hotel_system.pojo.entity.Collection;
import com.hzvictory.hotel_system.service.ICollectionService;
//import com.hzvictory.hotel_system.common.utils.ExcelUtil;
import com.hzvictory.hotel_system.common.core.page.TableDataInfo;

/**
 * 收藏表Controller
 *
 * @author hzvictory
 * @date 2025-07-24
 */
@RestController
@RequestMapping("/system/collection")
public class CollectionController extends BaseController
{
    @Autowired
    private ICollectionService collectionService;

    /**
     * 查询收藏表列表
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:list')")
    @GetMapping("/list")
    public TableDataInfo list(Collection collection)
    {
        startPage();
        List<Collection> list = collectionService.selectCollectionList(collection);
        return getDataTable(list);
    }

    /**
     * 导出收藏表列表
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:export')")
//    @Log(title = "收藏表", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, Collection collection)
//    {
//        List<Collection> list = collectionService.selectCollectionList(collection);
//        ExcelUtil<Collection> util = new ExcelUtil<Collection>(Collection.class);
//        util.exportExcel(response, list, "收藏表数据");
//    }

    /**
     * 获取收藏表详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(collectionService.selectCollectionById(id));
    }
    /**
     * 根据userId获取收藏表详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:query')")
    @GetMapping(value = "/list/{userId}")
    public TableDataInfo getInfoByUserId(@PathVariable("userId") Long userId)
    {
        startPage();
        List<Collection> list = collectionService.selectCollectionListByUserId(userId);
        return getDataTable(list);
    }

    /**
     * 新增收藏表
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:add')")
    @Log(title = "收藏表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Collection collection)
    {
        return toAjax(collectionService.insertCollection(collection));
    }

    /**
     * 修改收藏表
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:edit')")
    @Log(title = "收藏表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Collection collection)
    {
        return toAjax(collectionService.updateCollection(collection));
    }

    /**
     * 删除收藏表
     */
    //@PreAuthorize("@ss.hasPermi('system:collection:remove')")
    @Log(title = "收藏表", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(collectionService.deleteCollectionByIds(ids));
    }

    /**
     * 删除指定收藏表
     */
    @DeleteMapping("/info")
    public AjaxResult removeBYInfo(@RequestBody Collection collection)
    {
        return toAjax(collectionService.deleteCollectionByInfo(collection));
    }
}
